package com.watermeter.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.oa.android.R;
import com.watermeter.android.activity.DcbActivity;
import com.watermeter.android.activity.DownloadRouteActivity;
import com.watermeter.android.activity.JiaofeiActivity;
import com.watermeter.android.activity.LoginActivity;
import com.watermeter.android.activity.OlneSelectActivity;
import com.watermeter.android.activity.SaveServiceActivity;
import com.watermeter.android.activity.UpInfoActivity;
import com.watermeter.android.activity.YesCBActivity;
import com.watermeter.android.utils.UConstants;
import com.watermeter.android.utils.Util;


public class MainActivity extends Activity implements View.OnClickListener{

    private ImageView setting;
    private ImageView scan;
    private TextView comName;
    private TextView uName,bumen;
    private TextView textView[]=new TextView[6];
    private int[] id={R.id.dengj, R.id.lookRote,R.id.custom,R.id.donwling,R.id.update,R.id.updateChange};
    private long exitTime = 0;
    public static MainActivity mainActivity;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        x.Ext.init(getApplication());
//        // 设置是否输出debug
//        x.Ext.setDebug(true);
        mainActivity=this;
        setContentView(R.layout.activity_main_c);
        setting=(ImageView)findViewById(R.id.setting);
        comName=(TextView)findViewById(R.id.comName);
        uName=(TextView)findViewById(R.id.uName);
        bumen=(TextView)findViewById(R.id.bumen);
        comName.setText(UConstants.ComName);
        bumen.setText("部门："+UConstants.DepName);
        uName.setText("姓名："+UConstants.EmpName);
        scan=(ImageView)findViewById(R.id.scan);
        for (int i=0;i<id.length;i++){
            textView[i]=(TextView)findViewById(id[i]);
            textView[i].setOnClickListener(this);
        }
        setting.setOnClickListener(this);
        scan.setOnClickListener(this);
      String filePath=  Environment.getExternalStorageDirectory().getAbsolutePath() + "/CBFile/";
        Util.makeRootDirectory(filePath);

    }


    @Override
    public void onClick(View v) {
        Intent intent=new Intent();
        switch (v.getId()){
            case R.id.scan:
                new Util(this).setUser(UConstants.EmpId,"","0");
                intent.setClass(this, LoginActivity.class);
                startActivity(intent);
                finish();
                break;

            case R.id.dengj:
                intent.setClass(this, DcbActivity.class);
                startActivity(intent);
                break;
            case R.id.donwling:
                intent.setClass(this, DownloadRouteActivity.class);
                startActivity(intent);
                break;
            case R.id.setting:
                intent.setClass(this, SaveServiceActivity.class);
                intent.putExtra("type","2");
                startActivity(intent);
                break;

            case R.id.custom:
                intent.setClass(this, OlneSelectActivity.class);
                startActivity(intent);
                break;
            case R.id.update:
                intent.setClass(this, YesCBActivity.class);
                startActivity(intent);
                break;
            case R.id.updateChange:
                intent.setClass(this, UpInfoActivity.class);
                startActivity(intent);
                break;
            case   R.id.lookRote:
                intent.setClass(this, JiaofeiActivity.class);
                startActivity(intent);
                break;

    }
    }


//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        if (keyCode == KeyEvent.KEYCODE_BACK
//                && event.getAction() == KeyEvent.ACTION_DOWN) {
//            if ((System.currentTimeMillis() - exitTime) > 1500) {
//                Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
//                exitTime = System.currentTimeMillis();
//            } else {
//                this.finish();
//                System.exit(0);
//            }
//            return true;
//        }
//        return super.onKeyDown(keyCode, event);
//
//    }



}
